package com.example.service.impl;

import com.example.entity.Customer;
import com.example.entity.Goods;
import com.example.mapper.CustomerMapper;
import com.example.service.CustomerService;
import com.example.utils.PageBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public void insert(String name, String password, Integer category, String address) {
        LocalDateTime createTime = LocalDateTime.now();
        LocalDateTime updateTime = LocalDateTime.now();
        customerMapper.insert(name,password,category,address,createTime,updateTime);
    }

    @Override
    public void delete(Integer id) {
        customerMapper.delete(id);
    }

    @Override
    public void update(Integer id, String name, String password, Integer category, String address) {
        LocalDateTime updateTime = LocalDateTime.now();
        customerMapper.update(id,name,password,category,address,updateTime);
    }

    @Override
    public PageBean select(Integer page, Integer pageSize, Integer id, String name, Integer category, String address) {
        PageHelper.startPage(page, pageSize);
        List<Customer> customerList = customerMapper.select(id,name,category,address);
        Page<Customer> p = (Page<Customer>) customerList;
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }
}
